package com.youlu.campus.entity.commission;

import com.youlu.campus.base.base.EntityBase;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 分销者申请
 */
@Getter
@Setter
@Document(collection = "distributor_apply")
public class DistributorApply extends EntityBase {

    /**
     * 账号ID
     */
    @Indexed(unique = true, background = true)
    private String userId;

    /**
     * openId
     */
    private String openId;

    /**
     * 手机号
     */
    @Indexed(background = true)
    private String mobile;

    /**
     * 姓名
     */
    @Indexed(background = true)
    private String name;

    /**
     * 大学ID
     */
    private String universityId;

    /**
     * 大学名称
     */
    private String universityName;

    /**
     * 审核状态
     */
    private Integer status = DistributorApplyStatusEnum.NO_PASS.getValue();

    /**
     * 申请时间
     */
    private LocalDateTime applyTime;

    /**
     * 审核不通过备注
     */
    private String remark;


    private List<ApplyLog> applyLogList;

    /**
     * 审核人ID
     */
    private String auditorId;
    /**
     * 审核人姓名
     */
    private String auditorName;

    @Transient
    private Integer preStatus;
    @Transient
    private String preRemark;
    @Transient
    private String amount ="0";

    public ApplyLog initApplyLog(){
        ApplyLog applyLog = new ApplyLog();
        applyLog.setOptTime(this.applyTime);
        applyLog.setAuditorId(this.auditorId);
        applyLog.setAuditorName(this.auditorName);
        applyLog.setRemark(this.remark);
        applyLog.setStatus(this.status);
        return applyLog;
    }


    @Getter
    @Setter
   public class ApplyLog {
        private Integer status = DistributorApplyStatusEnum.NO_PASS.getValue();
        private LocalDateTime optTime;
        private String remark;
        private String auditorId;
        private String auditorName;
    }

    public DistributorCommission getDistributorCommission(){
        DistributorCommission distributorCommission = new DistributorCommission();
        distributorCommission.setMobile(this.mobile);
        distributorCommission.setUserId(this.userId);
        distributorCommission.setName(this.name);
        distributorCommission.setOpenId(this.openId);
        return distributorCommission;
    }
}
